package actions;
import javax.ejb.EJB;
import java.util.*;
import entities.*;
import javax.ejb.Local;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import utils.*;
import beans.*;
public class UpdateAccountAction extends ActionSupport {

    private static final long serialVersionUID = 6L;

    private User user;
    
    @EJB
    private UserManagerLocal userMan;
    
    private String message;
    
	public String execute()
    {
	
        	Object userIdObj=ActionContext.getContext().getSession().get("userId");
        	if(userIdObj==null){
        		message="Login session data not found";
        		return ERROR;
        	}
        	
        	//Now load the user object
        	userMan=new UserManager();
        	user.setUserId(((Integer)userIdObj).intValue());
        	boolean result=userMan.updateUser(user);
        	if(!result){
        		message = "Unable to save your data";
        		return ERROR;
        	}
        	message="Your account was updated successfully.";
        	return SUCCESS;
        
    }

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

   

}